package com.lenovo.nova.widget;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by scenic on 1/5/15.
 */
public class GetViewMaxWidth {

    private int viewMaxWidth;

    public int getMaxWidthByBackground(View view){
        Drawable drawable = view.getBackground();
        int backgoundWidth = 0;
        if(drawable != null){
            backgoundWidth = drawable.getIntrinsicWidth();
        }

        if(viewMaxWidth < backgoundWidth){
            viewMaxWidth = backgoundWidth;
        }


        if(view instanceof ViewGroup){
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                View childView = ((ViewGroup) view).getChildAt(i);
                getMaxWidthByBackground(childView);
            }
        }

        return viewMaxWidth;
    }


}
